package com.cjh.mybatis02.bind;

import com.cjh.mybatis02.session.SqlSession;
import lombok.Data;

import java.lang.reflect.Proxy;

/**
 * @description: 映射器代理工厂
 * @author: cjh
 * @date: 2023/5/23 - 20:14
 */
@Data
public class MapperProxyFactory<T> {

    private final Class<T> mapperInterface;

    @SuppressWarnings("unchecked")
    public T newInstance(SqlSession sqlSession){
        MapperProxy<T> proxy = new MapperProxy<>(sqlSession, mapperInterface);
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(),new Class[]{mapperInterface},proxy);

    }
}
